//package com.zlq.javaWeb3.filter;
//
//import com.zlq.javaWeb3.entity.User;
//
//import javax.servlet.*;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.annotation.WebInitParam;
//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;
//import java.io.IOException;
//
//@WebFilter(urlPatterns = "/*", initParams = {@WebInitParam(name = "encoding", value = "UTF-8")})
//public class HelloFilter implements Filter {
//
//    private String encoding = "UTF-8";
//
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//        String initParameter = filterConfig.getInitParameter("encoding");
//        System.out.println(initParameter);
//        if (!initParameter.isEmpty()){
//            this.encoding=initParameter;
//        }
//    }
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        HttpServletRequest request = (HttpServletRequest) servletRequest;
//        HttpServletResponse response = (HttpServletResponse) servletResponse;
//        request.setCharacterEncoding(encoding);
//        response.setCharacterEncoding(encoding);
//        long l = System.currentTimeMillis();
//        System.out.println("进去"+l);
//        filterChain.doFilter(request,response);
//        long l1 = System.currentTimeMillis();
//        System.out.println("出去"+l1);
//        System.out.println("一共用了"+(l1-l));
//        HttpSession session = request.getSession();
//        User user = (User) session.getAttribute("user");
//        if (user ==null || user.getName() == null){
//            request.getRequestDispatcher("oop.jsp").forward(servletRequest,servletResponse);
//            System.out.println("从新登录");
////            response.sendRedirect("oop.jsp");
//        }else {
//            System.out.println("正确");
//            filterChain.doFilter(request,response);
//        }
//
//    }
//
//    @Override
//    public void destroy() {
//        Filter.super.destroy();
//    }
//}
